package com.fc.mall.portal.controller;

import com.fc.mall.base.object.Result;
import com.fc.mall.portal.dto.NoticeBodyParam;
import com.fc.mall.portal.dto.NoticeType;
import com.fc.mall.portal.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Sunny on 2019/7/20.
 */
@RestController
@RequestMapping("/sms/sendNotice")
public class SmsController {

    @Autowired
    private SmsService smsService;

    @PostMapping
    public Result sendNotice(@RequestBody NoticeBodyParam noticeBody)
    {

        NoticeType noticeType = NoticeType.fromInt(noticeBody.getNoticeType());
        switch (noticeType)
        {
            case APPROVALNOTICE:
                smsService.approvalNotice(noticeBody.getMemberId(), noticeBody.getNickName(), noticeBody.getType(), noticeBody.getStatus(), noticeBody.getApprovalDate());
                break;
            case DELIVERYNOTICE:
                smsService.sendDeliveryOrderNotice(noticeBody.getMemberId(), noticeBody.getCompanyName(), noticeBody.getTrackingNumber(), noticeBody.getOrderSn(), noticeBody.getReceiver(), noticeBody.getReceiveAddress(), noticeBody.getDeliveryDate());
                break;
            case WITHDRAWNOTICE:
                smsService.withdrawNotice(noticeBody.getMemberId(), noticeBody.getAmount(), noticeBody.getApplyDate());
                break;
            default:
                break;
        }

        return Result.success();
    }
}
